package cn.com.ibibj.alignmentService.controller;

import cn.com.ibibj.alignmentService.common.param.RequestParam;
import cn.com.ibibj.alignmentService.handler.RedisRequestHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/alignment-test")
public class AlignmentController {
    @Resource
    RedisRequestHandler redisRequestHandler;
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public boolean alignmentAdd(@RequestBody RequestParam param) {
        try {
            redisRequestHandler.submitRequest(param.getIpAndPort(), param.getEndpoint(), param.getParams())
                    .subscribe(id -> System.out.println("用户请求已提交，ID: " + id));
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
